package com.ruoyi.integration.config;

import io.netty.channel.ChannelOption;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.netty.http.client.HttpClient;

import java.time.Duration;

@Configuration
public class WebClientConfig {

    @Bean
    public WebClient webClient(){

        HttpClient httpClient = HttpClient.create()
                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 300000) // 连接超时时间（毫秒）
                .responseTimeout(Duration.ofMinutes(10))
                .option(ChannelOption.SO_TIMEOUT, 60000); // 响应超时（毫秒）


        return WebClient.builder()
                .codecs(configurer -> configurer.defaultCodecs()
                        .maxInMemorySize(10 * 1024 * 1024))  // 修改缓冲区大小限制以避免处理第三方响应返回的二进制数据失败
                .clientConnector(new ReactorClientHttpConnector(httpClient))
                .build();
    }



}